package com.zhangyongyi.carhome.fragment.forum.featureddaily;

import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v4.widget.DrawerLayout;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.zhangyongyi.carhome.R;
import com.zhangyongyi.carhome.adapter.Forum.featureddaily.FeaturedDailyAdapter;
import com.zhangyongyi.carhome.fragment.forum.featureddaily.fineselection.FineSelectionFragment;
import com.zhangyongyi.carhome.fragment.forum.featureddaily.halloffame.HallOfFameFragment;
import com.zhangyongyi.carhome.fragment.forum.featureddaily.whole.WholeFragment;

import java.util.ArrayList;

/**
 * Created by dllo on 16/1/19.
 * 精选日报
 */
public class FeaturedDailyFragment extends Fragment implements View.OnClickListener {
    private ArrayList<Fragment> datas;
    private FeaturedDailyAdapter adapter;
    private TabLayout tabLayout;
    private ViewPager viewPager;
    private DrawerLayout drawerLayout;





    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_featured_daily, null);
        return view;
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);


        view.findViewById(R.id.iv_featured_daily).setOnClickListener(this);
        drawerLayout = (DrawerLayout) view.findViewById(R.id.drawLayout_featured_daily);

        view.findViewById(R.id.tv_whole_featured_daily).setOnClickListener(this);
        view.findViewById(R.id.tv_hall_of_fame_featured_daily).setOnClickListener(this);
        view.findViewById(R.id.tv_fine_selection_featured_daily).setOnClickListener(this);



        datas = new ArrayList<>();
        datas.add(new WholeFragment()); //全部
        datas.add(new HallOfFameFragment()); //名人堂
        datas.add(new FineSelectionFragment());//精挑细选



        tabLayout = (TabLayout) view.findViewById(R.id.tabLayout_featured_daily);
        viewPager = (ViewPager) view.findViewById(R.id.viewpager_featured_daily);
        adapter = new FeaturedDailyAdapter(getChildFragmentManager(), datas, getActivity());
        viewPager.setAdapter(adapter);

        //蓝色
        tabLayout.setSelectedTabIndicatorColor(Color.BLUE);
        tabLayout.setupWithViewPager(viewPager);


        for (int i = 0; i < tabLayout.getTabCount(); i++) {
            TabLayout.Tab tab = tabLayout.getTabAt(i);
            if (tab != null) {
                tab.setCustomView(adapter.getTabView(i));
            }
        }

    }


    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.iv_featured_daily:
                drawerLayout.openDrawer(Gravity.LEFT);
                break;
            case R.id.tv_whole_featured_daily:
                viewPager.setCurrentItem(0);
                break;
            case R.id.tv_hall_of_fame_featured_daily:
                viewPager.setCurrentItem(1);
                break;
            case R.id.tv_fine_selection_featured_daily:
                viewPager.setCurrentItem(2);
                break;


        }
    }
}
